Skip to content

No cancel lock - #1

Open
nullfail wants to merge 3 commits into
masterfrom
no-cancel-lock
Open

nullfail wants to merge 3 commits into
masterfrom
no-cancel-lock

Conversation

@nullfail

@nullfail nullfail commented Dec 4, 2026

Copy link
Copy Markdown
Owner

No description provided.

Raise the minimum Cap'n Proto version from 0.9 to 0.10.3. 0.10 added
CallContextHook::from(), needed by the next commit to hold a reference to
a request's call context.

0.10.3 is also the oldest 0.10 release not affected by CVE-2022-46149 so
requiring directly allow us to drop the CVE check.
Replace cancel_mutex/cancel_lock with a reference to the request's call
context (CallContextHook::from(call_context).addRef()), taken and released
on the event loop thread. Cancellation no longer frees the params and
results structs while a worker thread is using them, so on_cancel only sets
an atomic request_canceled flag and never blocks the event loop thread
waiting for the worker. This removes the class of deadlocks where a worker
holding the lock waits for the event loop (destroy(), destroying
ProxyClient params, any EventLoop::sync() call).

The lock also kept the Connection alive while the worker used it, because
~Connection cancels requests through m_canceler and on_cancel blocked on
the lock. Move the remaining Connection accesses on worker threads
(building ProxyClient and ProxyServer objects, setting m_thread_map) onto
the event loop thread with SyncValue()/syncRequest(), which skip the work
and throw InterruptException if the request was canceled. Reading
capabilities, including list items, also happens on the event loop thread
now via GetCapability(), because ClientHook reference counts are not
atomic.
Add "SyncValue:before" and "SyncValue:after" testing_hook_misc calls to
SyncValue(), so tests can disconnect right before or after the worker
thread builds a ProxyClient.

Add a sumBars() method taking a list of interfaces, and check that
canceling the request between list items interrupts the call instead of
deadlocking when the already-read item's ProxyClient is destroyed. Also
disconnect before and after a callback param's ProxyClient is built, to
check that the worker never uses the server Connection after it is
destroyed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant